<?
class uagent extends DM{
	//
	//
	//
	//
	//
	// VERSION:
	// AUTHOR: bugz
	// DATE: 24.12.2006
	//


	// VARIABLE DECLARATION
	var $id_uagent = "";
	var $txt_uagent = "";

	var $debugging=false;

	var $lista = "";


	// METHOD DECLARATION

	//DEBUG METHOD
	function debug($result,$operation=""){
		if ($result){
			if ($this->debugging){
				echo "<div style='font-size:10px;font-family:arial,sans;color:#FFFFFF;background-color:#008800'>OK: ";
				echo strtoupper($this->db_type)."($operation) - [No errors computed] ";
				echo "</div>";
			}
			return true;
		}else{
			if ($this->debugging){
				echo "<div style='font-family:arial,sans;color:#FFFFFF;background-color:#ff0000;font-size:10px;'>ERROR: ";
				echo strtoupper($this->db_type)."($operation) - [".$this->db->errDesc."] ".$this->db->errDesc;
				echo "</div>";
			}
			return false;
		}

	}

	//CONSTRUCTOR METHOD
	function uagent(){
		//LOAD THE DATABSE CLASS
		$this->loadClass('database','database');

		//INITIALIZE THE VARIABLES
		$this->id_uagent = "";
		$this->txt_uagent = "";
		$this->lista = array();

	}

	//GET METHODS
	//
	//
	//
	function getList(){

		//SQL STRING
		$sql="SELECT id_uagent FROM tbl_uagent WHERE 1";
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->fetch($sql)){
				$this->lista=$db->resultArray;
				return $this->debug(true,'get_list');
			}else{
				$this->errorReport("Error in the select",$sql);
				return $this->debug(false,"get_List - $sql");
			}
		}else{
			$this->errorReport("Could not conncet to the database",$db);
			return $this->debug(false,'get_list');
		}
	}

	function getById(){
		if ($this->id_uagent!=""){
			$sql = "select * from tbl_uagent where id_uagent='$this->id_uagent'";
			$db= new database();
			$db->debugging=$this->debugging;
			if ($db->connect()){
				if ($db->fetch($sql)){
					if (count($db->resultArray)==1){
						$this->id_uagent = $db->resultArray[0]["id_uagent"];
						$this->txt_uagent = $db->resultArray[0]["txt_uagent"];
						return true;
					}else{
						$this->errorReport("Error too many results.",$sql);
						return false;
					}
				}else{
					$this->errorReport("Error in the select",$sql);
					return false;
				}
			}else{
				$this->errorReport("Could not conncet to the database",$db);
				return false;
			}
		}
	}
	function checkSave(){
		$this->lista=array();
		$sql = "select id_uagent from tbl_uagent where txt_uagent='".$this->txt_uagent."'";
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->fetch($sql)){
				if (count($db->resultArray)==1){
					$this->id_uagent = $db->resultArray[0]["id_uagent"];
					return $this->save();
				}else{
					return $this->save();
				}
			}else{
				$this->errorReport("Error in the select",$sql);
				return false;
			}
		}else{
			$this->errorReport("Could not conncet to the database",$db);
			return false;
		}
	}
	function save(){
		if ($this->id_uagent==""){
			//insert
			$sql = "";
			$sql .= "INSERT INTO tbl_uagent(";
			$sql .= " id_uagent";
			$sql .= ", txt_uagent";
			$sql .= ") VALUES (";
			$sql .= " ''";
			$sql .= ", '$this->txt_uagent'";
			$sql .= ")";
		}else{
			//update
			$sql = "";
			$sql .= "UPDATE tbl_uagent SET";
			$sql .= " txt_uagent";
			$sql .= " = '$this->txt_uagent'";
			$sql .= " where ";
			$sql .= " id_uagent = '".$this->id_uagent."'";
		}
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->execute($sql)){
				return true;
			}else{
				$this->errorReport("Error in the select",$sql);
				return false;
			}
		}else{
			$this->errorReport("Could not conncet to the database",$db);
			return false;
		}
	}
	function delete(){
		$sql="DELETE FROM tbl_uagent WHERE id_uagent='$this->id_uagent'";
		$db= new database();
		$db->debugging=$this->debugging;
		if ($db->connect()){
			if ($db->execute($sql)){
				return true;
			}else{
				$this->errorReport("Error in the SQL:<BR>",$sql);
				return false;
			}
		}else{
			$this->errorReport("Error in the Connect");
			return false;
		}
	}


}
?>
